package com.itheima.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.itheima.pojo.Employee;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpSession;
import java.time.LocalDateTime;

/**
 * @author father
 * @date 2021/12/2
 * @apiNote
 **/
@Configuration
@Slf4j
public class MyMetaObjectHandler implements MetaObjectHandler {


    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("公共字段自动填充[insert]...");
        log.info(metaObject.toString());
        metaObject.setValue("create_time", LocalDateTime.now());
        metaObject.setValue("create_user", BaseContext.get());
        metaObject.setValue("update_time", LocalDateTime.now());
        metaObject.setValue("update_user", BaseContext.get());
    }
    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("公共字段自动填充[update]...");
        log.info(metaObject.toString());
        metaObject.setValue("update_time", LocalDateTime.now());
        metaObject.setValue("update_user", BaseContext.get());

    }


}
